package com.tms.goods.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.tms.goods.domain.TmsGoods;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.tms.goods.service.ITmsGoodsService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 订单Controller
 *
 * @author ruoyi
 * @date 2024-10-24
 */
@RestController
@RequestMapping("/goods")
public class TmsGoodsController extends BaseController
{
    @Autowired
    private ITmsGoodsService tmsGoodsService;

    /**
     * 查询订单列表
     */
    @RequiresPermissions("goods:goods:list")
    @GetMapping("/list")
    public TableDataInfo list(TmsGoods tmsGoods)
    {
        startPage();
        List<TmsGoods> list = tmsGoodsService.selectTmsGoodsList(tmsGoods);
        return getDataTable(list);
    }

    /**
     * 导出订单列表
     */
    @RequiresPermissions("goods:goods:export")
    @PostMapping("/export")
    public void export(HttpServletResponse response, TmsGoods tmsGoods)
    {
        List<TmsGoods> list = tmsGoodsService.selectTmsGoodsList(tmsGoods);
        ExcelUtil<TmsGoods> util = new ExcelUtil<TmsGoods>(TmsGoods.class);
        util.exportExcel(response, list, "订单数据");
    }

    /**
     * 获取订单详细信息
     */
    @RequiresPermissions("goods:goods:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tmsGoodsService.selectTmsGoodsById(id));
    }

    /**
     * 新增订单
     */
    @Log(title = "订单日志", businessType = BusinessType.INSERT)
    @RequiresPermissions("goods:goods:add")
    @PostMapping
    public AjaxResult add(@RequestBody TmsGoods tmsGoods)
    {
        tmsGoods.setStatus("待调度");
        return toAjax(tmsGoodsService.insertTmsGoods(tmsGoods));
    }

    /**
     * 修改订单
     */
    @Log(title = "订单日志", businessType = BusinessType.UPDATE)
    @RequiresPermissions("goods:goods:edit")
    @PutMapping
    public AjaxResult edit(@RequestBody TmsGoods tmsGoods)
    {
        return toAjax(tmsGoodsService.updateTmsGoods(tmsGoods));
    }

    /**
     * 删除订单
     */
    @Log(title = "订单日志", businessType = BusinessType.DELETE)
    @RequiresPermissions("goods:goods:remove")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tmsGoodsService.deleteTmsGoodsByIds(ids));
    }

    //统计订单
//    @RequiresPermissions("goods:goods:charts")
    @GetMapping("/charts")
    public TableDataInfo countGoods() {
//        List<TmsGoods> list = tmsGoodsService.countGoods();
        List<TmsGoods> list = tmsGoodsService.countGoods();
    	return getDataTable(list);
    }


    // 统计订单数量
    @GetMapping("/todo")
    public TableDataInfo todoGoods() {
//        List<TmsGoods> list = tmsGoodsService.countGoods();
        List<TmsGoods> list = tmsGoodsService.todoGoods();
        return getDataTable(list);
    }
}
